<template>
  <pro-layout
    :logo="logoRender"
    title="江河信息科技"
    :menus="menus"
    :collapsed="collapsed"
    :media-query="query"
    :is-mobile="isMobile"
    :handle-media-query="handleMediaQuery"
    :handle-collapse="handleCollapse"
    :i18n-render="i18nRender"
    v-bind="settings"
  >
    <!--    <template v-slot:menuRender>
      <div v-for="(menu, key) in menus" :key="key">
        {{  menu }}
      </div>
    </template>-->
    <!-- <template v-slot:menuHeaderRender>
      <div>
        <LogoSvg />
        <h1>江河信息科技</h1>
      </div>
    </template> -->
    <!-- <template v-slot:headerContentRender>
      <div>headerContentRender</div>
    </template> -->
    <template v-slot:rightContentRender>
      <div
        :class="['ant-pro-global-header-index-right', settings.layout === 'topmenu' && `ant-pro-global-header-index-${settings.theme}`]"
      >
        rightContentRender
      </div>
    </template>
    <template v-slot:footerRender>
      <div>footerRender</div>
    </template>
    <setting-drawer :settings="settings" @change="handleSettingChange" />
    <router-view />
  </pro-layout>
</template>

<script>
import { asyncRouterMap } from '../config/router.config'
import { i18nRender } from '../locales'

import defaultSettings from '@/config/defaultSettings'
import LogoSvg from '../assets/jxsl-logo.svg?inline'
import { CONTENT_WIDTH_TYPE } from '@/store/mutation-types'
export default {
  name: 'BasicLayout',
  data () {
    return {
      // base
      menus: [],
      // 侧栏收起状态
      collapsed: true,
      // 自动隐藏头部栏
      autoHideHeader: true,
      // 媒体查询
      query: {},
      // 布局类型
      layout: 'splitmenu', // 'sidemenu', 'topmenu', 'splitmenu'
      // 定宽: true / 流式: false
      contentWidth: 'Fluid', // layout of content: `Fluid` or `Fixed`, only works when layout is topmenu
      // 主题 'dark' | 'light'
      theme: 'dark',
      // 是否手机模式
      isMobile: false,
      settings: {
        // 布局类型
        layout: defaultSettings.layout, // 'sidemenu', 'topmenu'
        // CONTENT_WIDTH_TYPE
        contentWidth: defaultSettings.contentWidth,
        // 主题 'dark' | 'light'
        theme: defaultSettings.navTheme,
        // 主色调
        primaryColor: defaultSettings.primaryColor,
        fixedHeader: defaultSettings.fixedHeader,
        fixSiderbar: defaultSettings.fixSiderbar,
        colorWeak: defaultSettings.colorWeak,
        hideHintAlert: false,
        hideCopyButton: false
      }
    }
  },
  created () {
    this.menus = asyncRouterMap.find(item => item.path === '/').children
  },
  methods: {
    i18nRender,
    handleMediaQuery (val) {
      this.query = val
      if (this.isMobile && !val['screen-xs']) {
        this.isMobile = false
        return
      }
      if (!this.isMobile && val['screen-xs']) {
        this.isMobile = true
        this.collapsed = false
      }
    },
    handleCollapse (val) {
      this.collapsed = val
    },
    handleSettingChange ({ type, value }) {
      type && (this.settings[type] = value)
      switch (type) {
        case 'contentWidth':
          this.settings[type] = value
          break
        case 'layout':
          if (value === 'sidemenu') {
            this.settings.contentWidth = CONTENT_WIDTH_TYPE.Fluid
          } else if (value === 'topmenu') {
            this.settings.fixSiderbar = false
            this.settings.contentWidth = CONTENT_WIDTH_TYPE.Fixed
          } else if (value === 'splitmenu') {
            this.settings.fixSiderbar = false
            this.settings.contentWidth = CONTENT_WIDTH_TYPE.Fluid
          }
          break
      }
    },
    logoRender () {
      return <LogoSvg />
    }
    // footerRender() {
    //   return <div>custom footer</div>
    // },
  }
}
</script>

<style lang="less" scoped>
@import 'BasicLayout.less';
</style>
